<?php
include "includes/global.php";
$lang=READ_SESSION("LANG");

define("lang", $lang);

if($lang=='v'){
	include "lang/vietnamese.php";
	$configuration_id=1;
	$mod_contactsuccess = 'lien-he-thanh-cong';
}else{
	include "lang/english.php";
	$configuration_id=2;
	$mod_contactsuccess = 'contact-success';
}
///////////////////////////////////////////////////////

$name=$_POST["name"]?formatData($_POST["name"]):"";
$email=$_POST["email"]?formatData($_POST["email"]):"";
$phone=$_POST["phone"]?formatData($_POST["phone"]):"";
$company=$_POST["phone"]?formatData($_POST["company"]):"";
$address=$_POST["address"]?formatData($_POST["address"]):"";
$subject=$_POST["subject"]?formatData($_POST["subject"]):"";
$message=$_POST["message"]?formatData($_POST["message"]):"";

$send=$_POST["send"];

if($send=='yes'){
	$str_error=$error_email.$error_phone;
	if($str_error==""){
		$sql = "SELECT * FROM ".pre_table."configuration WHERE configuration_id='".$configuration_id."'";
		$rs = recordset($sql);
		$email_admin = $rs['configuration_email'];
		
		// ++ send mail	
		require("includes/phpmailer/class.phpmailer.php");
		$mail = new PHPMailer();
		$mail->FromName = $rs['configuration_company'];
		$mail->IsHTML(true);
		$mail->From     = $email;
		$mail->AddAddress($email_admin);
		//$mail->AddAddress("admin@websoftvietnam.net");		
		
		$mail->Subject = $subject;
		$mail->Body = '<h3>'.ContactFrom.'</h3>
						<b>'.Fullname.':</b> '.$name.'<br>
						<b>Email:</b> '.$email.'<br>
						<b>'.Phone.':</b> '.$phone.'<br>
						<b>'.Company.':</b> '.$company.'<br>
						<b>'.Address.':</b> '.$address.'<br>
						<b>'.Message.':</b> '.$message.'
						';


		if(!$mail->Send()){
		   $error_sendmail = ErrorEmail;
		   echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script>
					parent.document.frmContact.target = "_parent";		
					parent.document.getElementById("err").style.display="block";
					parent.document.getElementById("str_error").innerHTML="'.$error_sendmail.'";
				</script>';
			exit();	
		// -- send mail
		}else{
			echo '<script>
						parent.document.frmContact.target = "_parent";				
						parent.window.location.href="'.const_Web_Url.'index.php/'.$mod_contactsuccess.'";
					</script>';
			exit();
		}	
	}else{
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script>
				parent.document.frmContact.target = "_parent";		
				parent.document.getElementById("err").style.display="block";
				parent.document.getElementById("str_error").innerHTML="'.$str_error.'";
			</script>';
		exit();		
	}	
}
?>
